import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Modal, message } from 'antd';

const mapStateToProps = (state: any) => ({
  HandsetMng: state.HandsetMng,
});
class ConfirmDelModal extends PureComponent<any, any> {
  close = () => {
    const { closeModal } = this.props;
    closeModal();
  };
  ok = () => {
    const { dispatch, record } = this.props;
    dispatch({
      type: 'HandsetMng/getData',
      payload: { url: `/msalcohollock/handhelds/binding/state/${record.code}` },
      callback: (res: any) => {
        if (res.statusCode === '0') {
          this.delRecord();
        } else {
          message.error('手持机已绑定车辆，解绑后才可删除');
        }
      },
    });
  };
  // 删除
  delRecord() {
    const { dispatch, record, closeModal } = this.props;
    dispatch({
      type: 'HandsetMng/delData',
      payload: { url: `/msalcohollock/handhelds/${record.sid}` },
      callback: (res: any) => {
        if (res.statusCode === '0') {
          message.success('删除成功');
          closeModal('ref');
        }
      },
    });
  }
  render() {
    const { modalVisible } = this.props;
    return (
      <Modal title={'删除'} visible={modalVisible} onOk={this.ok} onCancel={this.close}>
        <div style={{ textAlign: 'center' }}>确认删除该设备吗</div>
      </Modal>
    );
  }
}
export default connect(mapStateToProps)(ConfirmDelModal);
